package cn.j2e.security;

import java.util.HashMap;

import com.cpms.dto.LoginUser;

/**
 * 用户登录信息类，存储用户login信息,该类为单体类
 */
public class LogonContext {
	
	private static LogonContext instance = null;
	// 已登录用户map
	private HashMap<String, LoginUser> LoginUserMap;
	
	private LogonContext() {
		LoginUserMap = new HashMap<String, LoginUser>();
	}

	public synchronized static LogonContext getInstance() {
		if (instance == null) {
			instance = new LogonContext();
		}
		return instance;
	}
	
	public void addLoginUser(String sid,LoginUser loginfo){
		LoginUserMap.put(sid, loginfo);
	}
	public LoginUser removeLoginUser(String sid){
		LoginUser info = LoginUserMap.remove(sid);
		if(info==null) return null;
		return info;
	}
	public LoginUser getLoginUser(String sid){
		return LoginUserMap.get(sid);
	}
	
}
